
import axios from "axios";
/*时间格式，时分秒
* */
export function Unix_timeStamp (x) {
  let timer = new Date(x);
  var y = timer.getFullYear();
  var m = timer.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = timer.getDate();
  d = d < 10 ? "0" + d : d;
  let hour =
    timer.getHours() < 10
      ? "0" + timer.getHours()
      : timer.getHours();
  let min =
    timer.getMinutes() < 10
      ? "0" + timer.getMinutes()
      : timer.getMinutes();
  let sec =
    timer.getSeconds() < 10
      ? "0" + timer.getSeconds()
      : timer.getSeconds();
  let oT =
    y + "-" + m + "-" + d + " " + hour + ":" + min + ":" + sec;
  return oT
}
/*时间格式，年月日
* */
export function Unix_timeStampDay (x) {
  let timer = new Date(x);
  var y = timer.getFullYear();
  var m = timer.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = timer.getDate();
  d = d < 10 ? "0" + d : d;
  let oT = y + "-" + m + "-" + d;
  return oT
}
/*导出下载
* */
export function postExcelFile (params, url) {//params是post请求需要的参数，url是请求ur1地址
  var form = document.createElement("form");//创建form表单节点
  form.style.display = 'none';
  form.action = url;
  form.method = "post";
  form.enctype = "application/vnd.ms-excel"
  // form.enctype = "application/x-www-form-urlencoded;charset=UTF-8";
  document.body.appendChild(form);
  for (var key in params) {
    var input = document.createElement("input");
    input.type = "hidden";
    input.name = key;
    input.value = params[key];
    form.appendChild(input);
  }
  form.submit();
  form.remove();//删除form表单节点
}
/*上传excle表格
* */
export function sendEcxel (url, data) {
  return new Promise((resolve, reject) => {
    axios({
      url: url,
      method: "post",
      data: data,
      responseType: 'blob'  //这一行一定要加！！！
    }).then((res) => {
      return resolve(res)
    }).catch(error => {
      return reject(error)
    })
  })
}


